<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<script type="text/javascript" src="js/web2/account.js"></script>
<script type="text/javascript">
$(function(){
/* 	$("#pay_duihuan").load("balance.htm?tranPage=pay_duihuan"); */
	$("#noEnoughMoney").hide();
	$("#noEnoughRmb").hide();
});

//验证整型类型
function checkInt(curcy){
	var patFinal=/^[0-9]+$/;
	if(curcy==null || curcy=="" ){
		return false;
	}else if(patFinal.test(curcy)==true){
		return true;
	}
}
//输入购买数量
function buyNumChange(){
	var buyNum=$("#buyNum").val();
	if(checkInt(buyNum)==true && storeNum(buyNum)==true){
		buyNum=parseInt(buyNum);
		var totalRmb=parseFloat(${totalRmb});
		var actualRmb=parseFloat(${myAccount.rmb});
		var price=parseFloat(${product.price});
		var needMoney=price*buyNum;
		if(checkPurchase(buyNum,price,totalRmb,actualRmb)){
			
			$("#needMoney").html(needMoney);
			
		}else{
			$("#needMoney").html(0);
			$("#buyNum").val("");
		}
	}else{
		$("#noEnoughMoney").hide();
		$("#noEnoughRmb").hide();
		$("#buyNum").val("");
       
	}
}
function checkPurchase(buyNum,price,totalRmb,actualRmb){
	var needMoney=price*buyNum;
	if(needMoney<=actualRmb){
		$("#noEnoughRmb").hide();
		$("#noEnoughMoney").hide();
		return true;
	}else if(needMoney>actualRmb && needMoney <=totalRmb){
		$("#noEnoughRmb").show();
		$("#noEnoughMoney").hide();
		return true;
	}else if(needMoney>totalRmb){
		$("#noEnoughRmb").hide();
		$("#noEnoughMoney").show();
		return false;
	}
}
function storeNum(buyNum){
	var amount =parseInt(${product.amount});
	if(buyNum<=amount && buyNum>0){
		return true;
	}else{
		alert("库存不足！");
		return false;
	}
	
}
</script>
<style>
#tb_duihuan{
width: 550px;
}
#td_duihuan{
width: 450px;
}
</style>
<div class="tcWrapper_y zhifuTotalWid">
    	<div class="tcHeader_y zhifuWid">
        	<b class="tcLTAngel_y"></b>
            <b class="tcRTAngel_y"></b>
        </div>
        <div class="ggrzWrap">
       	  <div class="ggTitle zhifuWid">
            	<h4 class="redColor">支付</h4>
                <a href="javascript:void(0)" onclick="$('#pay_dialog').hide();hideMask();">
               	 <img src="imgs/login-close.png" />
				</a>
       	  </div>
          <div class="ordCpName noBorder">
          		<p class="boxMT10"><span>商品名称：</span><i class="colorRed fontWeight">${product.title}</i></p>
                <p class="boxMT10"><span>数量：</span><input type="text" name="buyNum" id="buyNum" onkeyup="buyNumChange()"><label for="buyNum">请输入需要兑换的数量</label></p>
          </div>
          <div class="boxP5 backWhite">
          		<p>你需要<span id="needMoney">0</span>元现金，你的账户现金合计为<span>${totalRmb }</span>元。</p>
                <p class="redalarm" id="noEnoughMoney">注意：不能兑换此奖品。你的账户合计不够，不能兑换你需要的商品。</p>
                <p class="redalarm" id="noEnoughRmb">注意：现金不够系统将自动把你的果果币转换为现金。</p>
          </div>
        <!--   <span class="changexj">货币转换</span> -->
           <div class="boxPad5 tablePadd">
          		<a href="javascript:void(0)" class="ddNextBtn" onclick="GUOGUO.showOrderPage($('#buyNum').val(),'${product.identifier}')"><img src="imgs/ddpic01.png"></a>
          </div> 
          

      </div>
        <div class="tcBottom_y zhifuWid">
        	<b class="tcLBAngel_y"></b>
            <b class="tcRBAngel_y"></b>
        </div>
    </div>